home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Practical Algorithms for Image Analysis
/
Practical Algorithms for Image Analysis.iso
/
CH_5.7
/
XSGLL
/
PRLPAR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-11
|
2KB
|
75 lines
/*
* prlpar.c
*
* Practical Algorithms for Image Analysis
*
* Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
*/
/* PRLPAR: function returns distance and overlaps between 2
* nearly parallel lines
* usage: prlpar (ptO1, ptF1, ptO2, ptF2,
* &dist12, &dist21,
* &overlap12, &overlap21)
*/
#include <math.h>
#include <stdlib.h>
#include "lldef.h"
#include "xsgll.h"
#define OVERLAP 1 /* overlap exists */
#define NOOVERLAP 0 /* no overlap exists */
#define PERPENDICULAR -1 /* no nothing: lines are perpend. */
//#define ABS(A) (((A) > 0.0) ? (A): -(A)) /* absolute value */
/*
* evaluate (normalized) overlaps 12 and 21, as well as distances d12, d21
*/
void
prlpar (ptO1, ptF1, ptO2, ptF2, dist12, dist21, overlap12, overlap21)
struct spoint ptO1, /* initial and final pts of line 1 */
ptF1, ptO2, /* initial and final pts of line 2 */
ptF2;
double *dist12, /* perpendic. dist. between lines */
*dist21, *overlap12, /* overlap between line segments */
*overlap21;
{
register int defined12, /* 1 = overlap; 0 = none */
defined21;
register double minDist, /* min. dist. between lines */
absDist12, /* absolute values of distances */
absDist21;
/* find distance and overlap from line 1 to 2 and 2 to 1 */
defined12 = parallelpar (ptO1, ptF1, ptO2, ptF2, dist12, overlap12);
defined21 = parallelpar (ptO2, ptF2, ptO1, ptF1, dist21, overlap21);
/* make the distance equal to the minimum valid distance between lines */
absDist12 = ABS (*dist12);
absDist21 = ABS (*dist21);
if (defined12 == OVERLAP && defined21 == OVERLAP) {
minDist = (absDist12 < absDist21) ? absDist12 : absDist21;
*dist12 = (*dist12 >= 0.0) ? minDist : -minDist;
*dist21 = (*dist21 >= 0.0) ? minDist : -minDist;
}
else if (defined12 == OVERLAP) {
*dist21 = (*dist21 >= 0.0) ? absDist12 : -absDist12;
}
else if (defined21 == OVERLAP) {
*dist12 = (*dist12 >= 0.0) ? absDist21 : -absDist21;
}
else
*dist12 = *dist21 = 0.0;
}